﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should.Fluent;

namespace Is.Test.Fluent
{
    [TestClass]
    public class ContainsDictionaryExtensionsTest
    {
        [TestMethod]
        public void Test_IsNull()
        {
            IDictionary<int, string> sampleDictionary = null;
            sampleDictionary.Is().Null().Should().Be.True();
            sampleDictionary.Is().Not.Null().Should().Be.False();
            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Is().Null().Should().Be.False();
            sampleDictionary.Is().Not.Null().Should().Be.True();
        }

        [TestMethod]
        public void Test_IsEmpty()
        {
            IDictionary<int, string> sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Is().Empty().Should().Be.True();
            sampleDictionary.Is().Not.Empty().Should().Be.False();
            sampleDictionary.Add(0, "nulla");
            sampleDictionary.Is().Empty().Should().Be.False();
            sampleDictionary.Is().Not.Empty().Should().Be.True();

            IDictionary<int, string> nullsampleDictionary = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullsampleDictionary.Is().Empty());
        }

        [TestMethod]
        public void Test_IsNullOrEmpty()
        {
            IDictionary<int, string> sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Is().NullOrEmpty().Should().Be.True();
            sampleDictionary.Is().Not.NullOrEmpty().Should().Be.False();
            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Is().NullOrEmpty().Should().Be.True();
            sampleDictionary.Is().Not.NullOrEmpty().Should().Be.False();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Is().NullOrEmpty().Should().Be.False();
            sampleDictionary.Is().Not.NullOrEmpty().Should().Be.True();
        }

        [TestMethod]
        public void Test_Is_Contains()
        {
            string nullstring = null;

            IDictionary<int, string> sampleDictionary = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().Any(s => s.Value == "alma"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(0, "alma")));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().One(s => s.Value == "alma"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(0, "alma")));

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Is().Contains().Any(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().Any(null));
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            Func<string, bool> nullpredicate = null;


            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Is().Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().Any(null));
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Add(1, "alma");
            sampleDictionary.Add(2, "alom");
            sampleDictionary.Is().Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().Any(null));
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "alom").Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value.Is().StartsWith("alo")).Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.True();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Add(1, "alma");
            sampleDictionary.Add(2, "alom");
            sampleDictionary.Add(3, null);
            sampleDictionary.Is().Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().Any(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Contains().Any(s => s.Value == string.Empty).Should().Be.False();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Contains().Any(null));
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Contains().Item(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "alom").Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().StartsWith("alo")).Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == "cser").Should().Be.False();
            sampleDictionary.Is().Contains().One(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Contains().One(s => s.Value == string.Empty).Should().Be.False();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Contains().One(new KeyValuePair<int, string>(2, "alma")).Should().Be.False();

        }

        [TestMethod]
        public void Test_Is_Not_Contains()
        {
            string nullstring = null;

            IDictionary<int, string> sampleDictionary = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().Any(s => s.Value == "alma"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(0, "alma")));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().One(s => s.Value == "alma"));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(0, "alma")));

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == string.Empty).Should().Be.True();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().Any(null));
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(1, "alma")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == string.Empty).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.True();
            Func<string, bool> nullpredicate = null;


            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == string.Empty).Should().Be.True();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().Any(null));
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(1, "alma")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == string.Empty).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.True();

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Add(1, "alma");
            sampleDictionary.Add(2, "alom");
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == string.Empty).Should().Be.True();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().Any(null));
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(2, "alma")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "alom").Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().StartsWith("alo")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.StartsWith("alo")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == null).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == string.Empty).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(1, "alma")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(2, "alma")).Should().Be.True();

            sampleDictionary = new Dictionary<int, string>();
            sampleDictionary.Add(0, "alma");
            sampleDictionary.Add(1, "alma");
            sampleDictionary.Add(2, "alom");
            sampleDictionary.Add(3, null);
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "alma").Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().StartsWith("al")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value.Is().Not.Null() && s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Any(s => s.Value == string.Empty).Should().Be.True();
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => sampleDictionary.Is().Not.Contains().Any(null));
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().Item(new KeyValuePair<int, string>(2, "alma")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "alom").Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "alma").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().StartsWith("alo")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().Not.StartsWith("alo")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value.Is().Not.Null() && s.Value.Is().Not.StartsWith("al")).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == "cser").Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == null).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(s => s.Value == string.Empty).Should().Be.True();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(0, "alma")).Should().Be.False();
            sampleDictionary.Is().Not.Contains().One(new KeyValuePair<int, string>(2, "alma")).Should().Be.True();

        }
    }
}
